package com.cinyi.ormlite.core;

import java.io.Serializable;
import java.util.List;

import com.cinyi.ormlite.annotation.AnnotationNotFoundException;

/**
 * 基础数据结构定义
 * @author penghui
 *
 * @param <T>
 */
@SuppressWarnings({"rawtypes", "unchecked"})
public abstract class BaseModel<T extends BaseModel> extends ModelWrapper<T> implements Serializable { 
	/**
	 * 
	 */
	private static final long serialVersionUID = 873560356557095253L;

	/**
	 * 自定义排序<br>
	 * example: order by {field}
	 */
	private String orderby = null ;
	
	public BaseModel(){
	}
	
	/**
	 * 获取model配置
	 * @return TableConfig cfg
	 * @throws AnnotationNotFoundException e
	 */
	public TableConfig getConfig() throws AnnotationNotFoundException{
	    return TableConfigCache.getConfig(this.getClass());
	}
	
	/**
	 * 保存对象
	 */
	public void save(){
	    save((T)this);
	}
	
	/**
	 * 
	 * @return T t
	 */
	@SuppressWarnings("hiding")
    public T find(){
	    return findOne((T)this) ;
	}
	
	/**
	 * 
	 * @return T t
	 */
	@SuppressWarnings("hiding")
    public List<T> findAll(){
        return findAll((T)this) ;
    }
	
	public Integer deleteByID(){
        return deleteByID(getId(), getClass()) ;
    }
	
	public abstract String getId();

    public String getOrderby()
    {
        return orderby;
    }

    public void setOrderby(String orderby) {
        this.orderby = orderby;
    }

}
